﻿@model ThaireInvestmentWeb.Models.AddFixedIncomeModel
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
    $(document).ready(function () 
    {
        applyValidateDate();
        $( "#ragetingHistory" ).dialog({
            width: 500,
            autoOpen : false ,
            modal: true, 
            position: ['center',100] ,
            buttons: {
                close: function() { 
                    $(this).dialog("close"); 
                }
            }
        });

        $("#MaturityDate,#Data_CouponPaymentDate,#IssueDate,#RatingHistory_IssueUpdateDate,#RatingHistory_IssuerUpdateDate,#RatingHistory_GuarantorUpdateDate").datepicker(
      {
          dateFormat: 'dd/mm/yy',
          isBuddhist: true,
          showOn: 'button',
          showAnim: 'fadeIn',
          changeMonth: true,
          changeYear: true,
          showButtonPanel: true,
          buttonImage: '@Url.Content("~/Content/images/Calendar.png")',
          onSelect: function(dateText, inst) { 
              if(this.id == "MaturityDate" || this.id == "IssueDate")
              {
                  //alert($("#MaturityDate").val());
                  //alert($("#IssueDate").val());
                  getMaturityStatus($("#MaturityDate").val(),$("#IssueDate").val());
              }
          }
      });


        $("#SelectedCreditAgencyIssue").change(function () 
        {
            getForeign($(this).val(),  $("#IssueCreditAgencyForeign"));
          //  getRiskLevel();
        });

        $("#SelectedCreditAgencyIssuer").change(function () 
        {
            getForeign($(this).val(),  $("#IssuerCreditAgencyForeign"));
           // getRiskLevel();
        });


        $("#SelectedCreditAgencyGuarantor").change(function () 
        {
            getForeign($(this).val(),  $("#GuarantorCreditAgencyForeign"));
          //  getRiskLevel();
        });


        $("#SelectedIssueRating").change(function () 
        {
            getRiskLevel();
        });

        $("#SelectedIssuerRating").change(function () 
        {
            getRiskLevel();
        });

        $("#SelectedGuarantorRating").change(function () 
        {
            getRiskLevel();
        });
        
        
        

        $("#SelectedGuarantor").change(function () 
        {
            // alert($("#SelectedGuarantor option:selected").text());

            
            var otnTextBox =   $('#GuarantorOtherName');
            if($("#SelectedGuarantor option:selected").text()== 'Other')
            {
                otnTextBox.attr("disabled",false);
                otnTextBox.focus();
            }else{
                otnTextBox.val("");
                otnTextBox.attr("disabled",true);
            }
        });

        if($("#SelectedGuarantor option:selected").text()== 'Other')
        {
            $('#GuarantorOtherName').attr("disabled",false);
        }

        $("#CancelBtn").click(function (event)
        {
             
            //  showConfirm(null, testYes);
            showConfirm("ยกเลิก ?", CancelBtnAction);
            return false;
        });

        //$("#SaveBtn").click(function (event)
        //{
             
        //    //  showConfirm(null, testYes);
        //    showConfirm("ยืนยันการบันทึก", SaveBtnAction);
        //    return false;
        //});
        
        //$('#CancelBtn').click(function (event) 
        //{
        //   // alert("dd");
        //    if (confirm("ยกเลิก ?"))
        //    {
        //        window.location.href= 'ManageFixedIncomeSecurittes';
        //    }else
        //    {
        //        event.preventDefault();
        //        return false;
        //    }

        //});

        //$('#SaveBtn').click(function (event) 
        //{
        //  // alert("dd");
        //    var isValid = $('#mainForm').valid();
        //    if(isValid)
        //    {
        //        if (!confirm("ยืนยันการบันทึก"))
        //        {
        //            event.preventDefault();
        //        }
        //    }else
        //    {
                   
        //        event.preventDefault();
        //    }
        //});

    });
    
    function CancelBtnAction(event)
    {
        window.location.href= 'ManageFixedIncomeSecurittes';
    }

    //function SaveBtnAction(event)
    //{
    //    var isValid = $('#mainForm').valid();
    //    if (isValid)
    //    {
    //        var form = $('#mainForm');
    //        var fakeSubmit = genFakeSubmitBtn("SaveBtn", form)
    //        form.submit();
    //        fakeSubmit.remove();
    //        event.preventDefault();
    //        closeConfirm();
    //    } else
    //    {
    //        showErrorDlg("โปรดระบุข้อมูลให้ครบ");
    //        event.preventDefault();
    //        closeConfirm();
    //    }
    //}
    
    function openRetingHistoryPopup()
    {

        $.ajax({
            url:"@Url.Action("GetRatingHistory", "FixedIncome")",
              type: 'POST',
              async:   true,
              success: function(data) 
              {
                  $('#ragetingHistoryContent').empty().html(data);
                  
                 // alert(data);
                  $("#ragetingHistory").dialog('option', 'title','Rating Histories');
                  $("#ragetingHistory").dialog('open');
              },
              error : function (xhr, ajaxOptions, thrownError) {
                  alert(xhr.status);
                  alert(thrownError);
              }
          });

       
    }

    function getRiskLevel()
    {
        //SelectedIssueRating
        
        
       // String issueRating, String issueAgency, String issuerRating, String , String gurantRating, String 
            $.ajax({
                url:"@Url.Action("GetRiskLevel", "FixedIncome")"+ "?issueRating=" + encodeURIComponent($("#SelectedIssueRating").val())+ "&issueAgency=" + encodeURIComponent($("#SelectedCreditAgencyIssue").val()) 
                + "&issuerRating=" + encodeURIComponent($("#SelectedIssuerRating").val())+ "&issuerAgency=" + encodeURIComponent($("#SelectedCreditAgencyIssuer").val()) 
                + "&gurantRating=" + encodeURIComponent($("#SelectedGuarantorRating").val())+ "&gurantAgency=" + encodeURIComponent($("#SelectedCreditAgencyGuarantor").val()) ,
                type: 'POST',
                async:   false,
                success: function(data) 
                {
                    
                    //alert(data.RiskLevel);
                    $('#Data_RiskLevel').val(data.RiskLevel);
                }
            });
            return false;
     
    }

    function getForeign(creditAgencyID,target)
    {

      //  creditAgencyID = $(srcObj).val();
      //  alert( data.AgencyCountry);
       // var data = '';
        $.ajax({
            url: "@Url.Action("GetForeign", "FixedIncome")" + "?creditagencyID=" + encodeURIComponent(creditAgencyID),
            type: 'POST',
            success: function(data) 
            {
                //targetObj.val();
                target.val( data.AgencyCountry);
                getRiskLevel();
               // return false;
            }
        });
    }
    function getMaturityStatus(value,issueDate)
    {
        $.ajax({
            url: "@Url.Action("GetMaturityStatus", "FixedIncome")" + "?maturityDate=" + value+"&issueDate="+issueDate,
            type: 'POST',
            success: function(data) {
                $('#Data_MaturityStatus').val(data.MaturityStatus);
                $('#IssuerTermDsp').val(data.IssuerTermDsp);

                return false;
            }
        });
    }

    function getInvolvedType(id)
    {
        $.ajax({
            url: "@Url.Action("GetInvolvedType", "FixedIncome")" + "?id=" + id,
            type: 'POST',
            success: function(data) {
                // alert(data.InvolvedPartyTypeCode);
                $('#InvolvedPartyTypeNo').val(data.InvolvedPartyTypeCode);
                $('#InvolvedPartyTypeReferance').val(data.InvolvedPartyTypeReference);


                return false;
            }
        });
    }


</script>

@using (Html.BeginForm("AddfixedIncomeFormAction", "FixedIncome", FormMethod.Post, new { id = "mainForm" }))
{
    
    <table class="navi" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td style="width: 100%;">
                <div class="navi">Instrument Type > <a href="fixedIncomeList">Fixed Income List</a>> Header </div>
            </td>
        </tr>
    </table>

    <table class="tableheader" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
            <td height="38" align="center" style="width: 100%; text-align: center;">INPUT Fixed Income Securities</td>
        </tr>
    </table>

    <table width="951" border="0" align="center">
        <tr>
            <td>
                <div align="center">
                    @Html.ValidationSummary(true)
                </div>
            </td>
        </tr>
        <tr>
            <td>

                <table width="100%" border="0" align="center" cellspacing="2">
                    <tr>
                        <td width="300" height="31">&nbsp;</td>
                        <td align="right">
                            <div style="text-align: right">Create by : @Model.Data.CreateUserId </div>
                        </td>
                        <td width="5">&nbsp;</td>
                        <td width="139" align="right">
                            <div style="text-align: right">Create Time :@Model.Data.CreateTs</div>
                        </td>
                    </tr>
                    <tr>
                        <td width="300" height="31">&nbsp;</td>
                        <td align="right">
                            <div style="text-align: right">Update by : @Model.Data.UpdateUserId</div>
                        </td>
                        <td width="5">&nbsp;</td>
                        <td width="139" align="right">
                            <div style="text-align: right">Update Time :@Model.Data.UpdateTs</div>
                        </td>
                    </tr>
                </table>
                <table class="tableform" width="100%" border="3" align="center" cellspacing="2">
                    <tr>
                        <td width="212" style="text-align: right">Company Name <span class="error">*</span>:
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedCompany, Model.CompanyList)
                        </td>
                        <td width="188" align="right">
                            <div style="text-align: right">Maturity Status:</div>
                        </td>
                        <td>&nbsp;</td>
                        <td width="208">

                            @Html.TextBoxFor(model => model.Data.MaturityStatus, new { @readonly = "readonly" })
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right">
                            <div>
                                AssetClass <span class="error">*</span>:
                            </div>
                        </td>
                        <td>&nbsp;</td>
                         <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedAssetClass, Model.AssetClassList)
                        </td>
                       <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                       
                       <td style="text-align: right">
                            <div>
                                FullName(TH) :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                         <td style="width: 236px">

                            @Html.TextBoxFor(model => model.Data.FixedIncomeFullnameTH)

                        </td>
                         <td style="text-align: right">
                            <div>
                                FullName(EN) :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.Data.FixedIncomeFullnameEN)

                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right">
                            <div>
                                Issuer <span class="error">*</span>:
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedIssuer, Model.IssuerList)
                        </td>
                        <td style="text-align: right">Issuer Type :</td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedIssuerType, Model.IssuerTypeList)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                Symbol <span class="error">*</span>:
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.Symbol)

                        </td>
                         <td style="text-align: right">
                            <div>
                                Transaction Type :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                         <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedTransactionType, Model.TransactionTypeList)
                        </td>
                    </tr>
                    <tr>
                       
                        <td>
                            <div align="right">Guarantor :&nbsp; </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedGuarantor, Model.GuarantorList)<br/>
                            @Html.TextBoxFor(x => x.GuarantorOtherName, new { disabled = "disabled" })
                        </td>
                         <td>
                            <div align="right">Guarantor Type :&nbsp; </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedGuarantorTypeID, Model.GuarantorTypeList)
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                ISIN Code <span class="error">*</span> :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.IsinCode)
                            @Html.ValidationMessageFor(model => model.IsinCode)

                        </td>
                        <td>
                            <div align="right">Bond Type : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedBondType, Model.BondTypeList)
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right">Listed Status : </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.DropDownListFor(x => x.SelectedListedStatus, Model.ListedStatusList)
                        </td>
                        <td>
                            <div align="right">ครั้งที่ออก : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>

                            @Html.TextBoxFor(model => model.Data.NumberTime)
                            @Html.ValidationMessageFor(model => model.Data.NumberTime)

                        </td>
                    </tr>
              
                    <tr>
                        <td style="text-align: right">Initial Par / Unit :</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.Data.InitialParUnit, new { @class = "inputNumberField" , @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency6(@Model.Data.InitialParUnit)  })
                            @Html.ValidationMessageFor(model => model.Data.InitialParUnit)

                        </td>
                           <td style="text-align: right">Current Par / Unit :</td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">


                            @Html.TextBoxFor(model => model.Data.CurrentParUnit, new { @class = "inputNumberField"  , @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency6(@Model.Data.CurrentParUnit) })
                            @Html.ValidationMessageFor(model => model.Data.CurrentParUnit)
                        </td>
                    </tr>
                    <tr>
                         <td style="text-align: right">Redempton :</td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedRedempton, Model.RedemptonList)


                        </td>

                    
                        <td style="text-align: right">Amortize Schedule : </td>
                        <td>&nbsp;</td>
                        <td>

                         @if(Model.UpdateMode)
                         {
                             <text>
                               <input type="button" name="Submit24" value=" Amortizing Schedule " class="button" onclick="self.location.href = 'AmortizeSchedule?headerID=@Model.Data.FixincomesecuritiesHeaderId';" >
                            </text>
                         }else{
                              <text>
                               <input type="button" name="Submit24" value=" Amortizing Schedule " class="button"  disabled="disabled" >
                            </text>
                         }

                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right">Issue Size : </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.Data.IssueSize)
                            @Html.ValidationMessageFor(model => model.Data.IssueSize)

                        </td>
                        <td style="text-align: right">Coupon : </td>
                        <td>&nbsp;</td>
                        <td>

                            @Html.TextBoxFor(model => model.Coupon, new { @class = "inputNumberField" , @Value = ThaireInvestmentWeb.Util.WebUtil.FormatCurrency6(@Model.Data.Coupon)})
                            @Html.ValidationMessageFor(model => model.Coupon) % </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Issue Date : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.IssueDate, new {need_validateDate=true, @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.IssueDate) })
                            (Ex.31/12/2014) @Html.ValidationMessageFor(model => model.IssueDate)

                        </td>
                        <td>
                            <div align="right">&nbsp;Coupon payment date   : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.TextBoxFor(model => model.Data.CouponPaymentDate, new {need_validateDate=true, @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.Data.CouponPaymentDate) })
                            (Ex.31/12/2014) @Html.ValidationMessageFor(model => model.Data.CouponPaymentDate)

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">
                                &nbsp;Maturity Date  (dd/mm/yyyy)<span class="error">*</span>
                                :
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.TextBoxFor(model => model.MaturityDate, new {need_validateDate=true,  @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.MaturityDate) })
                            (Ex.31/12/2014) @Html.ValidationMessageFor(model => model.MaturityDate)

                        </td>
                        <td>
                            <div align="right">Calculation Method&nbsp; : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            @Html.DropDownListFor(x => x.SelectedCalculationMethod, Model.CalculationMethodList)

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Issue Term   : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">


                            @Html.TextBoxFor(model => model.IssuerTermDsp, new { @readonly = "readonly" })


                        </td>
                        <td>
                            <div align="right">Payment Frequency&nbsp; : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>

                            @Html.TextBoxFor(model => model.Data.PaymentFrequency)
                            @Html.ValidationMessageFor(model => model.Data.PaymentFrequency)

                            &nbsp; per Year </td>
                    </tr>

                    <tr>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Issue Rating    :</div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">

                            @Html.DropDownListFor(x => x.SelectedIssueRating, Model.IssueRatingList)
                        </td>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Credit Agency (Issue): </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">
                            @Html.DropDownListFor(x => x.SelectedCreditAgencyIssue, Model.CreditAgencyIssueList)

                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right" bgcolor="#E8ECFF">Issue Rating Update Date : </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">

                            @Html.TextBoxFor(model => model.RatingHistory.IssueUpdateDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.RatingHistory.IssueUpdateDate) })
                            @Html.ValidationMessageFor(model => model.RatingHistory.IssueUpdateDate)

                        </td>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Credit Agency (Issue): </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">

                            @Html.TextBoxFor(model => model.IssueCreditAgencyForeign, new { @readonly = "readonly" })
                       


                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Issuer Rating   : </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">
                        @Html.DropDownListFor(x => x.SelectedIssuerRating, Model.IssuerRatingList)

                        <td bgcolor="#E8ECFF">
                            <div align="right">Credit Agency (Issuer) :&nbsp; </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">
                            @Html.DropDownListFor(x => x.SelectedCreditAgencyIssuer, Model.CreditAgencyIssuerList)


                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right" bgcolor="#E8ECFF">Issuer Rating Update Date : </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">

                            @Html.TextBoxFor(model => model.RatingHistory.IssuerUpdateDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.RatingHistory.IssuerUpdateDate) })
                            @Html.ValidationMessageFor(model => model.RatingHistory.IssuerUpdateDate)

                        </td>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Credit Agency (Issuer) :&nbsp; </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">
                         
                              @Html.TextBoxFor(model => model.IssuerCreditAgencyForeign, new { @readonly = "readonly" })

                            @* FOREIGN*@

                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Guarantor Rating   : </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">
                            @Html.DropDownListFor(x => x.SelectedGuarantorRating, Model.GuarantorRatingList)

                            &nbsp;
                        </td>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Credit Agency (Guarantor) :&nbsp; </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">

                            @Html.DropDownListFor(x => x.SelectedCreditAgencyGuarantor, Model.CreditAgencyGuarantorList)

                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: right" bgcolor="#E8ECFF">Guarantor Rating Update Date : </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">

                            @Html.TextBoxFor(model => model.RatingHistory.GuarantorUpdateDate, new { @readonly = "readonly", @Value = ThaireInvestmentWeb.Util.WebUtil.FormatDate(@Model.RatingHistory.GuarantorUpdateDate) })
                            @Html.ValidationMessageFor(model => model.RatingHistory.GuarantorUpdateDate)

                        </td>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Credit Agency (Guarantor) :&nbsp; </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">

                           
                              @Html.TextBoxFor(model => model.GuarantorCreditAgencyForeign, new { @readonly = "readonly" })
                          
                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#E8ECFF">
                            <div align="right">Risk Level  : </div>
                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td style="width: 236px" bgcolor="#E8ECFF">

                            @Html.TextBoxFor(model => model.Data.RiskLevel)
                            @Html.ValidationMessageFor(model => model.Data.RiskLevel)


                        </td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF">&nbsp;</td>
                        <td bgcolor="#E8ECFF" style="text-align: right">
                             <input type="button" onclick="openRetingHistoryPopup();return false" class="button"  id="ratinghistoryPopup" name="ratinghistoryPopup" value="History"/>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Liquidity    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td colspan="4">

                            @*<input checked="checked" type="checkbox" />*@
                            @Html.CheckBoxFor(model => model.IsTierISelected)

                            Tier I&nbsp; 
                                @*<input style="width: 50px" name="buy32225" type="text" id="buy32225" value="100">*@

                            @Html.TextBoxFor(model => model.Data.LiquidityTierIPercent)
                            @Html.ValidationMessageFor(model => model.Data.LiquidityTierIPercent)
                            %
                            <br />
                            @*<input type="checkbox" />*@
                            @Html.CheckBoxFor(model => model.IsTierIISelected)

                            Tier II&nbsp;
                                @*<input style="width: 50px" name="buy32225" type="text" id="Text1">*@

                            @Html.TextBoxFor(model => model.Data.LiquidityTierIiPercent)
                            @Html.ValidationMessageFor(model => model.Data.LiquidityTierIiPercent)

                            %
                            <br />
                            @Html.CheckBoxFor(model => model.IsLowLiquiditySelected)
                            Low Liquidity&nbsp;
                                @*<input style="width: 50px" name="buy32225" type="text" id="Text2" />*@
                            @Html.TextBoxFor(model => model.Data.LiquidityLowLiquidityPercent)
                            @Html.ValidationMessageFor(model => model.Data.LiquidityLowLiquidityPercent)
                            %
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">Involved Party Type Name    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">

                            @Html.DropDownListFor(x => x.SelectedInvolvedPartyType, Model.InvolvedPartyTypeNameList, new { onchange = "getInvolvedType(this.value)" })
                        </td>
                        <td>
                            <div align="right">Involved Party Type No. : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>

                            @Html.TextBoxFor(model => model.InvolvedPartyTypeNo, new { @readonly = "readonly" })

                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">รหัสอ้างอิง คปภ. (A-E)    : </div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">
                            @Html.TextBoxFor(model => model.InvolvedPartyTypeReferance, new { @readonly = "readonly" })
                            &nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right"></div>
                        </td>
                        <td>&nbsp;</td>
                        <td style="width: 236px">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
                <table width="95%" border="0" align="center" style="height: 38px">
                    <tr>
                        <td style="height: 38px">
                            <div align="center">
                                <input id="SaveBtn" type="button" name="SaveBtn" value=" Submit " class="button" need-confirm="true"  >
                                &nbsp;&nbsp; 
                                <input id="CancelBtn" type="button" name="CancelBtn" value=" Cancel " class="button" >
                                &nbsp;&nbsp;
                                <input id="EditBtn"  type="button" name="EditBtn" value=" Edit " class="button">
                            </div>
                        </td>
                    </tr>

                </table>
                @{ if (Model.UpdateMode)
                   {
                    <table width="95%" border="0" align="center">
                        <tr>
                            <td>
                                <div align="center" style="text-align: left">
                                    <input type="button" name="PurchaseBtn" value=" Purchase / Subscription " class="button" onClick="go('@Url.Action("AddFixedIncomePurchase", "FixedIncome", new { fixedIncomeID = Model.Data.FixincomesecuritiesHeaderId })    ');" >
                                    &nbsp;&nbsp; 
                                    <input type="button" name="Submit2" value=" Back" class="button"
                                        onclick="self.location.href = 'ManageFixedIncomeSecurittes';">
                                </div>
                            </td>
                        </tr>
                    </table>
                
                   }
                }




                


                <br>
            </td>
        </tr>

    </table>
    <div style="width:99%; overflow: auto;">
      
             @if (Model.TransactionHistory != null && Model.TransactionHistory.Count > 0)
             {
                 var grid = new WebGrid(source: Model.TransactionHistory, ajaxUpdateContainerId: "gridselected", rowsPerPage: 25,canSort:false);
                        @grid.GetHtml(htmlAttributes: new { id = "gridselected" }, tableStyle: "tablelist", headerStyle: "headertable", displayHeader: @Model.TransactionHistory.Count > 0,
            columns: grid.Columns(
            
                grid.Column(header: "NO.", format: item => (item.WebGrid.Rows.IndexOf(item) + 1) + (grid.PageIndex * grid.RowsPerPage), canSort: false),
             
     
                grid.Column( header: "TTM (Yrs.)",style:"columndecimal" ,format: @<text> @ThaireInvestmentWeb.Util.WebUtil.NonApplicableIfZero(item.TimeToMaturityDate ) </text>),
                   grid.Column(columnName: "TransactionType", header: "Trans.", canSort: false),
      
                grid.Column( header: "Trade Date", format: @<text> @ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.TradeDate ) </text>),
                grid.Column( header: "Settle. Date", format: @<text> @ThaireInvestmentWeb.Util.WebUtil.FormatDate(item.SettlementDate ) </text>),
                grid.Column( header: "Unit",style:"columnNumber", format: @<text> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(item.TransactionUnit ) </text>),
                grid.Column( header: "Remain Unit",style:"columnNumber" ,format: @<text> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency0(item.RemainUnit ) </text>),

                grid.Column( header: "Cost Yield",style:"columnNumber",format: @<text> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.CostYieldYTM ) </text>),
                grid.Column( header: "Purchase (THB)",style:"columnNumber",format: @<text> @ThaireInvestmentWeb.Util.WebUtil.FormatCurrency5(item.PurchaseValueLocalTHB ) </text>),
                      grid.Column(header: "Detail", format:
             @<text>
                           @if (item.TransactionID != null && (int)item.TransactionID!=0)
                           {
                               if ("Guarantee".Equals(item.TransactionType))
                               {
                                <input type="image" onClick="go('@Url.Action("FixedIncomeGuarantee", "FixedIncome", new { purchaseID = item.PurchaseID ,transactionID = item.TransactionID})');return false;"  src="@Url.Content("~/Content/images/b_edit.gif")"  title="แก้ไข"/>
                                   
                               }else{
                                <input type="image" onClick="go('@Url.Action("FixedIncomeSale", "FixedIncome", new { purchaseID = item.PurchaseID,transactionID = item.TransactionID })');return false;"  src="@Url.Content("~/Content/images/b_edit.gif")"  title="แก้ไข"/>
                                   
                               }
                              // if("Sale")
                            }else
                            {
                                <input type="image" onClick="go('@Url.Action("EditPurchase", "FixedIncome", new { purchaseID = item.PurchaseID })');return false;"  src="@Url.Content("~/Content/images/b_edit.gif")"  title="แก้ไข"/>
                            }
            </text>)));
             }
            
            
        
    </div>  
    
    <div id="ragetingHistory" style="display: none">
  <div style="width:100%;border:1px" id="ragetingHistoryContent"></div>
       
  </div>

    
    
         <a name="grid-anchor"></a>
                <script type="text/javascript">
                    $(function () {
                        $('th a, tfoot a').live('click', function () {
                            $(this).attr('href', '#grid-anchor');
                        });
                    });
                </script>    
    @Html.HiddenFor(x => x.UpdateMode);
    @Html.HiddenFor(x => x.RatingHistory.RatingHistoryId);
    @Html.HiddenFor(x => x.Data.FixincomesecuritiesHeaderId);
}